4 ...\PTVR_Researchers\Python_Scripts\Experiments\visual_search.py
12 from PTVR.Data.Callback import AddInteractionPassedToCallback, EndCurrentScene,ChangeObjectOutline,ChangeAudioSettings
14 from numpy
import array
24 viewpoint_position = array ([0, height_of_head, 0])
30 number_of_distractor = 512
32 radial_distance_min_max_values = array([2, 15])
41 hand = LaserContingency.RIGHT_HAND
49 sound_end_of_block =
"applaudisement.mp3"
50 sound_wrong_response =
"buzzer.ogg"
51 handcontroller_id = my_world.handControllerRight.id
52 configurations_set = set()
55 if(random_value == 1):
56 value = random.randint (0, 1)
58 color_object = color_base
60 color_object = color_distractor
62 my_object =
Sphere(size_in_meters= array([0.2, 0.2, 0.2]), color = color_object)
64 my_object =
Cube(size_in_meters= array([0.2, 0.2, 0.2]), color = color_base)
68 reticle_pointing_at_object = PointedAt (target_id = my_object.id,
69 activation_cone_origin_id=handcontroller_id,
70 activation_cone_radius_deg=1, activation_cone_depth=500, mode=
"press",
71 event_name=
"object_is_pointed_at")
72 reticle_NOT_pointing_at_object = PointedAt (target_id = my_object.id,
73 activation_cone_origin_id=handcontroller_id,
74 activation_cone_radius_deg=1, activation_cone_depth=500, mode=
"release",
75 event_name=
"object_is_not_pointed_at")
76 return reticle_pointing_at_object, reticle_NOT_pointing_at_object
83 return callback_outline_on,callback_outline_off
86 print(
"Creating an experiment to study visual search in various 3D regions...")
88 my_initial_scene = CheckScene ( my_world = my_world,
89 are_both_hand_controllers_visible=
True,
90 text_information =
"In this experiment you have "\
91 "to search for the red cube \n among over objects " \
92 "by pointing at it and pressing the trigger.\n" \
93 "When you are ready to start, please press the trigger.")
94 my_world.add_scene (my_initial_scene)
97 my_scene = VisualScene (is_right_hand_controller_visible =
True)
100 my_laser_beam = PointingLaser ( hand_laser = hand,
101 laser_color = my_laser_color,
103 my_scene.place_pointing_laser ( my_laser_beam )
104 my_scene.AddPointingCursor(my_laser_beam)
107 my_world.translate_coordinate_system_along_current(translation = viewpoint_position)
109 audio_wrong =
AudioSource(audioFile=sound_wrong_response, is_playing_directly=
False)
110 my_scene.place(audio_wrong,my_world)
111 while len(configurations_set) < number_of_distractor+1:
113 radialdistance = random.uniform(radial_distance_min_max_values [0],
114 radial_distance_min_max_values [1])
115 eccentricity = random.gauss(90, 40)
116 halfmeridian = random.randint(0, 360)
117 configuration = (radialdistance, eccentricity, halfmeridian)
118 if tuple(configuration)
not in configurations_set:
119 configurations_set.add(tuple(configuration))
121 configurations = [list(config)
for config
in configurations_set]
122 target_configuration = random.choice(configurations)
123 print(
"my target is at np.array([radial_distance,eccentricity,half_meridian)) : " +
124 str(target_configuration))
125 for config
in configurations:
126 radialdistance = config[0]
127 eccentricity = config[1]
128 halfmeridian = config[2]
129 if(config != target_configuration):
132 my_object =
Cube(size_in_meters= array([0.2, 0.2, 0.2]), color=color_target)
133 my_object.set_perimetric_coordinates(radialDistance=radialdistance,
134 eccentricity=eccentricity, halfMeridian=halfmeridian)
135 my_scene.place(my_object, my_world)
136 inside,outside = create_events_when_pointing_at_objects (my_object)
139 press =
HandController(valid_responses=[
'right_trigger'],mode=
"press",event_name=
"press")
140 if(config != target_configuration):
145 my_scene.AddInteraction(events=[inside], callbacks=[add,outline_on])
146 my_scene.AddInteraction(events=[outside], callbacks=[remove,outline_off])
154 my_scene.AddInteraction(events=[inside], callbacks=[add,outline_on])
155 my_scene.AddInteraction(events=[outside], callbacks=[remove,outline_off])
158 my_world.add_scene(my_scene)
160 my_world.reset_coordinate_system()
162 calibration =
CheckScene(my_world = my_world,text_information=
"Congratulations!",are_both_hand_controllers_visible =
True)
164 calibration.place(audio,my_world)
165 my_world.add_scene(calibration)
168 print(
"The .json file corresponding to this experiment has been created.")
171 if __name__ ==
"__main__":
def LaunchThe3DWorld(jsonFileCategory="Externals")
def new_objects(random_value)
def create_events_when_pointing_at_objects(my_object)
def create_callbacks_to_change_objects(my_object)